<template>
  <div style="position: relative;">
    <el-row>
      <el-col span="3" :offset="3" id="str">
        新邮箱：
      </el-col>
      <el-col span="10">
        <el-input v-model="email" placeholder="请输入内容" ></el-input>
      </el-col>
    </el-row>
    <br />
    <el-row>
      <el-col span="8" style="position: absolute;left: 374px;">
        <el-input v-model="code" placeholder="请输入内容" class="code"></el-input>
         <el-button type="primary" @click="sendcode()" id="getCode" style="position: absolute;left: 255px;">获取验证码</el-button>
      </el-col>
    </el-row>
    <br />
    <el-button type="primary" @click="setPwd()" style="margin-top: 80px;margin-left: 650px;">修改</el-button>
    <div style="margin-left: 650px; margin-top: 140px;">
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <span>是否确认修改</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="setPassword()">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
 export default{
   name:"SetPhone",
   data(){
   	return{
      email:"",
      code:"",
      dialogVisible:false,
   	}
   },
   methods:{
      setPwd(){
        this.dialogVisible=true;
      },
      setPassword(){
        if(this.code==null || this.code == "" || this.email == null || this.email == ""){
          alert("验证码或邮箱不能空")
          this.dialogVisible=false;
        }else{
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;//邮箱验证
          if(reg.test(this.email)){
            this.$http.get("/account/MailboxVerification2",{
              	params:{
              		activeCode:this.code,
                  email:this.email
              	}
              }).then(resp=>{
              	if(resp.data.code == 200){
                  console.log(resp.data)
                  this.dialogVisible=false;
                  // localStorage.removeItem("")
                  localStorage.setItem("user",JSON.stringify(resp.data))
                  alert("修改成功")
                  this.$router.push("/PersonalCenter")
                }else{
                  alert(resp.data.message)
                }
              })
          }else{
            alert("邮箱格式有误")
          }
        }
      },
      sendcode(){
        if(this.email == null || this.email == ""){
          alert("邮箱不能为空")
        }else{
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;//邮箱验证
          if(reg.test(this.email)){
            alert(this.email)
            this.$http.get("/account/MailboxVerification1",{
              params:{
                email:this.email
              }
            }).then(resp=>{
            	if(resp.data.code==200){
                alert("验证码已发送，请注意接收")
              }else{
                alert(resp.data.message)
              }
            })
          }else{
            alert("邮箱格式有误")
          }
        }
      }
   }
 }
</script>

<style>

</style>
